package com.caiwangdai.app.origin.list.delegator

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.widget.ProgressBar
import android.widget.TextView
import com.caiwangdai.app.R
import com.caiwangdai.app.extension.setOnClickListenerPro
import kotlinx.android.synthetic.main.content_list_loading_footer.view.*

/**
 * @project KotLinProject
 * @author 艹羊
 * @date 2017/6/16 上午11:53
 * @description 列表底部加载Footer
 */
class LoadingFooter {
    val mAnimationDuration: Long = 400

    var mLoadingFooter: View
    var mLoadingText: TextView
    var mProgress: ProgressBar

    var mState: State = State.Idle

    enum class State {
        Idle, TheEnd, Loading
    }

    constructor(context: Context) {
        mLoadingFooter = LayoutInflater.from(context).inflate(R.layout.content_list_loading_footer, null)
        mLoadingFooter.setOnClickListenerPro { }
        mProgress = mLoadingFooter.progressBar
        mLoadingText = mLoadingFooter.textView
        setState(State.Idle)
    }


    fun setState(status: State) {
        mState = status
        mLoadingFooter.visibility = View.VISIBLE

        when (status) {
            State.Idle -> {
                mLoadingFooter.visibility = View.GONE
            }
            State.Loading -> {
                mLoadingText.text = "正在加载更多数据"
                mLoadingText.visibility = View.VISIBLE
                mLoadingText.animate().withLayer().alpha(1f).duration = (mAnimationDuration)
                mProgress.visibility = View.VISIBLE
            }
            State.TheEnd -> {
                mLoadingText.text = "没有更多了"
                mLoadingText.visibility = View.VISIBLE
                mLoadingText.animate().withLayer().alpha(1f).duration = (mAnimationDuration)
                mProgress.visibility = View.GONE
            }

        }
    }



}